var vm_jieyujingfeituihui = new Vue({
    el: "#jieyujingfeituihui",
    data: {
        deptid: $("#deptid").val(),		// 单位ID
        jigoujibie: $("#jigoujibie").val(),

        tuikuanlist: [],// 退款list
        tuikuanid: '',//退款id

        tuikuanMonthList:[],//退款详情列表
        tingboList:[],//停拨明细list

        shouKuanMonthList:[],
        daituikuanList:[],
        checkArr:[],

        search:{
            deptname:'',
            zhuanjia:''
        },//停拨明细搜索字段

        tuikuanitemid:'',
        chakan:{
            zhuanjianame: '',
            deptname:''
        },//查看搜索

        piciList:[], //批次list

        tuikuanAdd: {
            list:[]
        },//退款

        pageindex1: 1,		// 查询分页初始化页
        pagesize1: 10,		// 查询分页初始化页面大小
        pageCount1: 0,		// 总页数
        recordCount1: 0,	// 总记录数
        targetpage1: '', 	// 目标页

        pageindex2: 1,		// 查询分页初始化页
        pagesize2: 10,		// 查询分页初始化页面大小
        pageCount2: 0,		// 总页数
        recordCount2: 0,	// 总记录数
        targetpage2: '', 	// 目标页

    },
    created: function () {
        var _this = this;
        _this.bindTuikuanList();
        // _this.bindPiciList()

    },
    watch: {
        //监控分页情况，刷新列表
        pageindex1: function () {
            this.bindPiciList()
        },

        pagesize1: function () {
            this.bindPiciList()
        },

        pageindex2: function () {
            this.bindTuikuanList()
        },

        pagesize2: function () {
            this.bindTuikuanList()
        },
    },
    methods: {

        bindTuikuanMonthList: function (id) {
            var _this = this;
            $.post('/system/zhiliu/findZhiliuByTuikuanjiluId', {
                tuikuanjiluid: id,
                xingming: _this.chakan.zhuanjianame,
                deptname: _this.chakan.deptname
            }, function (ppData) {
                if (ppData != null) {
                    if (ppData.result == "1") {
                        var data = ppData.resultContent;
                        _this.tuikuanMonthList = data;
                    } else {
                        layer.alert(ppData.message)
                    }
                }
            }, "json");
        },
        toChakan: function (id) {
            var _this = this;
            _this.tuikuanitemid = id
            _this.bindTuikuanMonthList(id)
            $("#chakanModalLabel").html("退款详情");
            // $("#modal-dialog").attr("style","width:1200px;");
            $("#chakanModal").modal();
        },
        chakan_search:function () {
            var _this = this;
            _this.bindTuikuanMonthList(_this.tuikuanitemid);
        },
        chakan_search_reset:function () {
            var _this = this;
            _this.chakan.deptname=''
            _this.chakan.zhuanjianame=''
            _this.bindTuikuanMonthList(_this.tuikuanitemid);
        },
        bindNewJingfeipiciDeptMonthList: function (jingfeipiciitem) {
            var _this = this;
            $.post('/system/newjingfeideptmonth/monthlist', {
                jingfeipiciid: jingfeipiciitem.jingfeipiciid,
                deptid: jingfeipiciitem.deptid
            }, function (ppData) {
                if (ppData != null) {
                    if (ppData.result == 1) {
                        var data = ppData.resultContent;
                        _this.shouKuanMonthList = data;
                    } else {
                        layer.alert(ppData.message);
                    }
                }
            }, "json");
        },
        bindPiciList: function () {
            var _this = this;
            $.post('/system/newjingfeidept/findDaishoukuanList', {
                deptid: _this.deptid,
                picimingcheng: "",
/*                pageindex: _this.pageindex1,
                pagesize: _this.pagesize1,*/
            }, function (ppData) {
                if (ppData != null) {
                    if (ppData.result == 1) {
                        var data = ppData.resultContent;
                        if(data.length>0)_this.piciList = data.filter(item => item.isshoukuan == 1)
/*                        var pageInfo = data.PageInfo;
                        _this.pageindex1 = pageInfo.pageIndex;
                        _this.pageCount1 = pageInfo.pageCount;
                        _this.recordCount1 = pageInfo.recordCount;
                        _this.targetpage1 = '';*/
                    } else {
                        layer.msg(ppData.message);
                    }
                }
            });
        },
        toXiangqing: function (jingfeipiciitem) {
            $("#shoukuanxiangqingLabel").html("收款详情");
            this.bindNewJingfeipiciDeptMonthList(jingfeipiciitem)
            $("#shoukuanxiangqingModal").modal();
        },

        // 根据单位ID查询专家变动申请信息
        bindTuikuanList: function () {
            var _this = this;
            $.post('/system/tuikuanjilu/tuikuanlist', {
                deptid: _this.deptid,
                pageindex: _this.pageindex2,
                pagesize: _this.pagesize2,
            }, function (ppData) {
                if (ppData != null) {
                    if (ppData.result == "1") {
                        var data = ppData.resultContent;
                        _this.tuikuanlist = data.tuikuanlist;
                        var pageInfo = data.PageInfo;
                        _this.pageindex2 = pageInfo.pageIndex;
                        _this.pageCount2 = pageInfo.pageCount;
                        _this.recordCount2 = pageInfo.recordCount;
                        _this.targetpage2 = '';
                    } else {
                        layer.alert(ppData.message)
                    }
                }
            }, "json");
        },
        //停拨明细list
        bindTingboList: function () {
            var _this = this;
            $.post('/system/tuikuan/tingbolist', {
                deptid: _this.deptid,
                zhuanjia: _this.search.zhuanjia,
                deptname: _this.search.deptname,
            }, function (ppData) {
                if (ppData != null) {
                    if (ppData.result == "1") {
                        var data = ppData.resultContent;
                        _this.tingboList = data;
                    } else {
                        layer.alert(ppData.message)
                    }
                }
            }, "json");
        },
        bindShoukuanList: function () {
            var _this = this;
            $.post('/system/newjingfeideptmonth/tuikuanlist', {
                deptid: _this.deptid,

            }, function (ppData) {
                if (ppData != null) {
                    if (ppData.result == "1") {
                        var data = ppData.resultContent;
                        _this.daituikuanList = data;

                    } else {
                        layer.alert(ppData.message)
                    }
                }
            }, "json");
        },
        toTuikuan: function () {
            $.modal.openOptions({
                url:"/system/jintieguanli/addtuikuan",
                title:"选择退款",
                width:1400,
                height:800,
                btn:['发起退款', '关闭'],
                yes: function(index, layero) {
                    //点击第一个按钮处理逻辑
                    layero.find("iframe")[0].contentWindow.submit()
                    layer.close(index);
                },
                btn2: function(index, layero){
                    //点击第二个按钮处理逻辑
                    layer.close(index);
                },

            });
        },
        refresh:function(){
            var _this = this;

            _this.bindYue();
            _this.bindTuikuanList();
        },
        //退款
        tuikuan: function () {
            var _this = this;
            for(var i = 0; i < _this.daituikuanList.length; i++){
                if(_this.daituikuanList[i].tuikuanjine>0) {
                    _this.tuikuanAdd.list.push({
                        tuikuanjine: _this.daituikuanList[i].tuikuanjine,
                        jingfeideptmonthid: _this.daituikuanList[i].id,
                        jingfeipiciid: _this.daituikuanList[i].jingfeipiciid
                    })
                }
            }
            _this.tuikuanAdd.deptid = _this.deptid
            $.ajax({
                type: 'post',
                dataType: 'json',
                url: '/system/tuikuan/tuikuanAdd',
                data: JSON.stringify(_this.tuikuanAdd),
                contentType:"application/json",
                success: function (result) {
                    layer.open({
                        time: 1000,
                        btn: [],
                        content: "提交退款成功!",
                    });
                    _this.refresh();
                    $("#tuikuanModal").modal('hide');
                },
            })

        },
        //停拨经费明细
        toTingbo:function () {
            this.search.deptname = ''
            this.search.zhuanjia = ''
            this.bindTingboList()
            $("#tingboModalLabel").html("停拨经费明细");
            $("#tingboModal").modal();
        },
        reset:function () {
            this.search.deptname = ''
            this.search.zhuanjia = ''
            this.bindTingboList()

        },
        //检查项目数据
        checkInputData: function () {
            if (!$.trim(this.biandong.zhuanjiaid)) {
                layer.alert("请选择变动的专家！");
                return false;
            }

            if (!$.trim(this.biandong.biandongleixing)) {
                layer.alert("请选择变动的类型");
                return false;
            }

            return true;
        },
        Chakan: function (jingfeipiciid) {
            $.modal.openTab("单位滞留经费明细", "/system/yue/dept_zhiliu?jingfeipiciid="+jingfeipiciid);
        },
        //首页
        firstPage1: function () {
            this.pageindex1 = 1;
        },
        //尾页
        lastPage1: function () {
            this.pageindex1 = this.pageCount1;
        },
        //上一页
        prePage1: function () {
            var prePage = ((this.pageindex1 - 1) <= 0) ? 1 : (this.pageindex1 - 1);
            this.pageindex1 = prePage;
        },
        //下一页
        nextPage1: function () {
            var nextPage = ((this.pageindex1 + 1) >= this.pageCount1) ? this.pageCount1 : (this.pageindex1 + 1);
            this.pageindex1 = nextPage;
        },
        //跳到目标页
        targetPage1: function () {
            if (this.targetpage1 != '' && this.targetpage1 <= this.pageCount1 && this.targetpage1 > 0) {
                this.pageindex1 = this.targetpage1;
                this.targetpage1 = '';
            }
        },

        //首页
        firstPage2: function () {
            this.pageindex2 = 1;
        },
        //尾页
        lastPage2: function () {
            this.pageindex2 = this.pageCount2;
        },
        //上一页
        prePage2: function () {
            var prePage = ((this.pageindex2 - 1) <= 0) ? 1 : (this.pageindex2 - 1);
            this.pageindex2 = prePage;
        },
        //下一页
        nextPage2: function () {
            var nextPage = ((this.pageindex2 + 1) >= this.pageCount2) ? this.pageCount2 : (this.pageindex2 + 1);
            this.pageindex2 = nextPage;
        },
        //跳到目标页
        targetPage2: function () {
            if (this.targetpage2 != '' && this.targetpage2 <= this.pageCount2 && this.targetpage2 > 0) {
                this.pageindex2 = this.targetpage2;
                this.targetpage2 = '';
            }
        },

    },
})